Base get_fingerprint on a PackageId
authorAlex Crichton <alex@alexcrichton.com>
Fri, 25 Jul 2014 02:14:18 +0000 (19:14 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 25 Jul 2014 02:32:49 +0000 (19:32 -0700)
The fingerprinting code was erroneously using all sources from a manifest when
calculating the fingerprint which meant that sources not yet downloaded were
attempted to be fingerprinted.

The correct source to fingerprint is located in the SourceId field of the
resolved PackageId.

Closes #259

src/cargo/core/package.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
tests/test_cargo_compile_git_deps.rs
tests/test_cargo_compile_path_deps.rs
tests/test_cargo_compile_plugins.rs

index 96175b9a134ace5d131a068c09bdd4bd4efe556e..40b59d99ebd2a470bea7742885ad5b797d0e6531 100644 (file)
@@ -12,9 +12,9 @@ use core::{
     Summary
 };
 use core::dependency::SerializedDependency;
-use util::{CargoResult, graph, Config};
+use util::{CargoResult, graph};
 use serialize::{Encoder,Encodable};
-use core::source::{SourceId, SourceSet, Source};
+use core::source::{SourceId, Source};
 
 // TODO: Is manifest_path a relic?
 #[deriving(Clone)]
@@ -116,20 +116,6 @@ impl Package {
         ret.push_all(self.manifest.get_source_ids());
         ret
     }
-
-    pub fn get_fingerprint(&self, config: &mut Config) -> CargoResult<String> {
-        let mut sources = self.get_source_ids();
-        // Sort the sources just to make sure we have a consistent fingerprint.
-        sources.sort_by(|a, b| {
-            let a = (&a.kind, a.location.to_string());
-            let b = (&b.kind, b.location.to_string());
-            a.cmp(&b)
-        });
-        let sources = sources.iter().map(|source_id| {
-            source_id.load(config)
-        }).collect::<Vec<_>>();
-        SourceSet::new(sources).fingerprint(self)
-    }
 }
 
 impl Show for Package {
index df17c0d7faab59006f1d0d32879d2018442a5b06..1f6325eae7ebac22e5e14faacc5e8b0125ff6811 100644 (file)
@@ -5,7 +5,7 @@ use std::io::{fs, File};
 use core::{Package, Target};
 use util;
 use util::hex::short_hash;
-use util::{CargoResult, Fresh, Dirty, Freshness};
+use util::{CargoResult, Fresh, Dirty, Freshness, Config};
 
 use super::job::Job;
 use super::context::Context;
@@ -75,8 +75,8 @@ pub fn prepare(cx: &mut Context, pkg: &Package,
 
 fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target])
             -> CargoResult<(bool, String)> {
-    let new_pkg_fingerprint = format!("{}{}", cx.rustc_version,
-                                      try!(dep.get_fingerprint(cx.config)));
+    let dep_fingerprint = try!(get_fingerprint(dep, cx.config));
+    let new_pkg_fingerprint = format!("{}{}", cx.rustc_version, dep_fingerprint);
 
     let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets));
 
@@ -103,3 +103,9 @@ fn fingerprint(package: String, profiles: u64) -> String {
     let hasher = SipHasher::new_with_keys(0,0);
     util::to_hex(hasher.hash(&(package, profiles)))
 }
+
+fn get_fingerprint(pkg: &Package, config: &mut Config) -> CargoResult<String> {
+    let source_id = pkg.get_package_id().get_source_id();
+    let source = source_id.load(config);
+    source.fingerprint(pkg)
+}
index 3a0f52b2c7c9ee8b06bdb6e5df31354acf8491f8..a295e85bc4593ef8e10267b169cfcb1e3642e706 100644 (file)
@@ -1,4 +1,5 @@
 use std::io::File;
+use std::path;
 
 use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
 use support::{cargo_dir};
@@ -99,6 +100,60 @@ test!(cargo_compile_simple_git_dep {
       execs().with_stdout("hello world\n"));
 })
 
+test!(override_git_dep {
+    let p = project("foo");
+    let root = p.root().clone();
+    let p = p
+        .file(".cargo/config", format!(r#"
+            paths = ['{}/baz']
+        "#, root.display()))
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.bar]
+            path = "bar"
+        "#)
+        .file("src/main.rs", "extern crate bar; fn main() {}")
+        .file("bar/Cargo.toml", r#"
+            [package]
+
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.baz]
+            git = 'git://example.com/path/to/nowhere'
+        "#)
+        .file("bar/src/lib.rs", "extern crate baz;")
+        .file("baz/Cargo.toml", r#"
+            [package]
+
+            name = "baz"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+        "#)
+        .file("baz/src/lib.rs", "");
+
+    assert_that(p.cargo_process("cargo-build"),
+        execs()
+        .with_stdout(format!("{compiling} baz v0.5.0 (file:{dir}{sep}baz)\n\
+                              {compiling} bar v0.5.0 (file:{dir})\n\
+                              {compiling} foo v0.5.0 (file:{dir})\n",
+                             compiling = COMPILING, dir = root.display(),
+                             sep = path::SEP))
+        .with_stderr(""));
+
+    assert_that(&p.bin("foo"), existing_file());
+
+    assert_that(
+      cargo::util::process(p.bin("foo")),
+      execs().with_stdout(""));
+})
+
 test!(cargo_compile_git_dep_branch {
     let project = project("foo");
     let git_project = git_repo("dep1", |project| {
index 3d73e809ced06389d794f82e4f34e7d580a48391..194f10e529ed23b132fc211bbf0dfcbf10739e1d 100644 (file)
@@ -161,8 +161,7 @@ test!(cargo_compile_with_transitive_dev_deps {
 
             [dev-dependencies.baz]
 
-            version = "0.5.0"
-            path = "baz"
+            git = "git://example.com/path/to/nowhere"
 
             [[lib]]
 
@@ -172,22 +171,6 @@ test!(cargo_compile_with_transitive_dev_deps {
             pub fn gimme() -> &'static str {
                 "zoidberg"
             }
-        "#)
-        .file("bar/baz/Cargo.toml", r#"
-            [project]
-
-            name = "baz"
-            version = "0.5.0"
-            authors = ["wycats@example.com"]
-
-            [[lib]]
-
-            name = "baz"
-        "#)
-        .file("bar/baz/src/baz.rs", r#"
-            pub fn gimme() -> &'static str {
-                "nope"
-            }
         "#);
 
     assert_that(p.cargo_process("cargo-build"),
index 98396c8e52c0db7c1dd9ba30b4819ecea6178ab6..80e64088bc8ec1f8a5ad0769372e4ec6259f4e71 100644 (file)
@@ -1,10 +1,5 @@
-use std::os;
-use std::path;
-
-use support::{project, execs, basic_bin_manifest};
-use support::{RUNNING, COMPILING};
-use hamcrest::{assert_that, existing_file};
-use cargo::util::process;
+use support::{project, execs};
+use hamcrest::assert_that;
 
 fn setup() {
 }